package o;

import android.content.Context;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.hms.api.Api.ApiOptions.HasOptions;
import com.huawei.hms.api.ConnectionResult;
import com.huawei.hms.api.HuaweiApiClient;
import com.huawei.hms.api.HuaweiApiClient.ConnectionCallbacks;
import com.huawei.hms.api.HuaweiApiClient.OnConnectionFailedListener;
import com.huawei.hms.support.api.client.ResultCallback;
import com.huawei.hms.support.api.client.Status;
import com.huawei.hms.support.api.hwid.HuaweiId;
import com.huawei.hms.support.api.hwid.HuaweiIdSignInOptions.Builder;
import com.huawei.hms.support.api.hwid.SignInResult;

public class eoh {
    private HuaweiApiClient ˊ;

    static class a implements OnConnectionFailedListener {
        private a() {
        }

        public void onConnectionFailed(ConnectionResult connectionResult) {
            Logger.ˋ("AccountSignInHelper", "onConnectionFailed: " + connectionResult.getErrorCode() + ", " + connectionResult.getErrorMessage());
        }
    }

    static class b implements ResultCallback<SignInResult> {
        private eoh ॱ;

        public /* synthetic */ void onResult(Object obj) {
            ˎ((SignInResult) obj);
        }

        public b(eoh o_eoh) {
            this.ॱ = o_eoh;
        }

        public void ˎ(SignInResult signInResult) {
            int statusCode = signInResult.getStatus().getStatusCode();
            Logger.ˎ("AccountSignInHelper", "sign in result: " + statusCode);
            if (statusCode == 0) {
                UserSession.getInstance().setAccessToken(signInResult.getSignInHuaweiId().getAccessToken());
                eon.ॱ().ˏ(300);
            } else {
                UserSession.getInstance().setAccessToken("");
                eon.ॱ().ˏ(301);
            }
            if (this.ॱ.ˊ != null) {
                this.ॱ.ˊ.disconnect();
            }
        }
    }

    static class d implements ConnectionCallbacks {
        private eoh ॱ;

        public d(eoh o_eoh) {
            this.ॱ = o_eoh;
        }

        public void onConnected() {
            Logger.ˎ("AccountSignInHelper", "onConnected, prepare to sign in");
            this.ॱ.ˊ();
        }

        public void onConnectionSuspended(int i) {
            Logger.ˋ("AccountSignInHelper", "onConnectionSuspended: " + i);
        }
    }

    public void ˎ() {
        Logger.ˎ("AccountSignInHelper", "enter sign in");
        ˊ(ContentManager.getInstant().getContext());
        this.ˊ.connect(null);
    }

    private void ˊ(Context context) {
        HasOptions build = new Builder().requestAccessToken().build();
        ConnectionCallbacks dVar = new d(this);
        this.ˊ = new HuaweiApiClient.Builder(context).addApi(HuaweiId.SIGN_IN_API, build).addConnectionCallbacks(dVar).addOnConnectionFailedListener(new a()).build();
    }

    private void ˊ() {
        if (this.ˊ.isConnected()) {
            HuaweiId.HuaweiIdApi.signOut(this.ˊ).setResultCallback(new ResultCallback<Status>(this) {
                final /* synthetic */ eoh ˋ;

                {
                    this.ˋ = r1;
                }

                public /* synthetic */ void onResult(Object obj) {
                    ˏ((Status) obj);
                }

                public void ˏ(Status status) {
                    if (status != null) {
                        int statusCode = status.getStatusCode();
                        Logger.ˎ("AccountSignInHelper", "sign out result: " + statusCode);
                        if (statusCode == Status.SUCCESS.getStatusCode()) {
                            HuaweiId.HuaweiIdApi.signInBackend(this.ˋ.ˊ).setResultCallback(new b(this.ˋ));
                            return;
                        }
                        return;
                    }
                    Logger.ˋ("AccountSignInHelper", "sign out result: null status");
                }
            });
        } else {
            Logger.ˋ("AccountSignInHelper", "sign in client is not connected");
        }
    }
}
